﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RMS.Utils.RoleProvider;
using RMS.DataAccess.Entities;
using RMS.DataAccess.Repositories;
using RMS.DataAccess.Common;
using RMS.Utils.Authentication;

namespace RMS.Web.Shell.Services
{

    public class RoleProviderService : IRoleProvider
    {
        IAuthentication _iAuthentication;
        RolesRepository _rolesRepository;
        public RoleProviderService(RolesRepository rolesRepository, IAuthentication iAuthentication)
        {
            _rolesRepository = rolesRepository;
            _iAuthentication = iAuthentication;
        }

        public string[] GetUserRoles()
        {
            List<string> roles = new List<string>();
            EntityResult<Roles> entityResult = _rolesRepository.Find(e => e.EmployeeID = _iAuthentication.CurrentLogedInMember.Id);
            foreach (Roles role in entityResult)
            {
                roles.Add(role.Role);
            }
            return roles.ToArray();
        }
    }
}
